<template>
  <div style="flex:1;" class="flex">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='search' v-ref:cri>
       <div novalidate class="form-inline" partial>
         <div class="form-group">
           <input  type="text" class="form-control" v-model="model.f_price_type" placeholder='气价类型'
           condition="f_price_type = '{}'" v-next-el="qjmc"
           :size="model.f_price_type ? model.f_price_type.length*2 : 4">
         </div>
         <div class="form-group">
           <input  type="text" class="form-control" v-model="model.f_price_name" placeholder='气价名称'
           condition="f_price_name = '{}'" v-next-el="cx" v-el:qjmc
           :size="model.f_price_name ? model.f_price_name.length*2 : 4">
         </div>
         <div class="form-group">
           <button class="btn btn-success width-100" @click="$parent.$parent.search()" v-el:cx>查询</button>
         </div>
         <div class="form-group">
           <button class="btn btn-success width-100" @click="$parent.$parent.add()">新增气价</button>
         </div>
       </div>
      </criteria>
      <data-grid  :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
             <th>序号</th>
             <th>气价信息</th>
             <th>执行日期</th>
             <!-- <th>状态</th> -->
             <th>使用户数</th>
          </tr>
        </template>
        <template partial='body'>
          <tr>
            <td style="text-align:center">{{$index+1}}</td>
            <td style="text-align:center">
              {{row.f_price_id}}&nbsp;&nbsp;{{row.f_price_type}}&nbsp;&nbsp;{{row.f_price_name}}&nbsp;&nbsp;
              {{row.f_user_type}}&nbsp;&nbsp;{{row.f_gasproperties}}&nbsp;&nbsp;{{row.f_stairmonths}}
            </td>
            <td style="text-align:center">{{row.f_perform_date}}
                </td>
                <!-- 还剩余{{row.f_end_date - row.f_perform_date}} -->
            <!-- <td style="text-align:center">{{row.f_state}}</td> -->
            <td style="text-align:center">{{row.usercount}}</td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

<script>
/**
*阶梯气价查询列表
*/
import { PagedList } from 'vue-client'

export default {
  data () {
    return {
      model: new PagedList('rs/sql/getGasPriceInfo', 20,
       {orderitem: '"' + this.orderitem + '"'})
    }
  },
  props: {
    orderitem: {
      type: String,
      default: 'f_price_id'
    },
    row: {}
  },
  ready () {
    this.search()
  },
  methods: {
    search () {
      this.$refs.paged.$refs.cri.search()
    },
    add () {
      this.$dispatch('add')
    }
  },
  watch: {
    'model.rows.length' (val) {
      if (val === 1) {
        this.$refs.paged.$refs.grid.select(this.model.rows[0])
      }
    }
  }
}
</script>
